<?php
namespace Plugin\Consult;

class Bootstrap
{
    public function boot()
    {

        add_hook_filter('admin.components.sidebar.menus', function ($data) {
            $data[] = [
                'route'    => 'consult.index',
                'icon' => 'bi bi-people',
                'title'    => trans('Consult::common.title'),
                'prefixes' => ['consult'],
            ];

            return $data;
        });
        add_hook_filter('role.permissions.plugin', function ($data) {
            $data[] = [
                'title'       => trans('Consult::common.title'),
                'permissions' => [
                    [
                        'code' => 'consult_index',
                        'name' => trans('Consult::common.title'),
                    ],
                ],
            ];

            return $data;
        });
        add_hook_blade('footer.services.before', function ($callback, $output, $data) {
            $data[] = [
                'route'    => 'consult.advisory',
                'title'    => trans('Consult::common.title'),
            ];
            return '<style>.app-s-iframe-box{position: fixed;z-index:99999999;right: 20px;bottom: 50px;box-shadow:0 0 8rem 0 rgba(0, 0, 0, 0.1), 0rem 2rem 4rem -3rem rgba(0, 0, 0, 0.5);background: #ffffff;border-radius: 10px;overflow: hidden;max-height: 600px;height: 100% !important;max-width: 400px;width: 100%;}.app-s-iframe-box-button{box-shadow: 0 6px 18px rgba(0, 0, 0, .07);position: fixed;right: 0px;bottom: 80px;z-index: 9999;width: 80px;min-height:180px;}@media screen and (max-width:720px){.app-s-iframe-box{max-height:80%;max-width:100%;right:0px;bottom:0px;padding-bottom: env(safe-area-inset-bottom);}.app-s-iframe-box-button{width:60px;min-height:140px;border-radius:38px;}}</style><iframe id="ConsultIframe" class="app-s-iframe-box-button" src="/advisory"></iframe><script>window.addEventListener(`message`,function(event){if(event.data=="scroll"){window.scroll({top:0,behavior:"smooth"})}if(event.data.includes("product")){const product_id_get_push=event.data.split("_");window.location.href="/products/"+product_id_get_push[1]}if(event.data.includes("indent")){const indent_id_get_push=event.data.split("_");window.location.href="/account/orders/"+indent_id_get_push[1]}if(event.data=="open"){document.getElementById("ConsultIframe").classList.add("app-s-iframe-box");document.getElementById("ConsultIframe").classList.remove("app-s-iframe-box-button")}if(event.data=="close"){document.getElementById("ConsultIframe").classList.add("app-s-iframe-box-button");document.getElementById("ConsultIframe").classList.remove("app-s-iframe-box")}if(event.data.includes("px")){document.getElementById("ConsultIframe").style.cssText="height:"+event.data}},false);</script>';
        });
    }
}
